package com.molichuxing.gateway.bff.car.services.impl;

import com.alibaba.fastjson.JSON;
import com.molichuxing.framework.dto.Paged;
import com.molichuxing.framework.utils.DateUtil;
import com.molichuxing.framework.utils.ObjectCastUtil;
import com.molichuxing.gateway.bff.car.convertor.Convert;
import com.molichuxing.gateway.bff.car.entity.request.create.CarLicencePlateCreateVo;
import com.molichuxing.gateway.bff.car.entity.request.modify.CarLicencePlateModifyVo;
import com.molichuxing.gateway.bff.car.entity.response.*;
import com.molichuxing.gateway.bff.car.services.CarCheckBffService;
import com.molichuxing.gateway.bff.car.services.LicencePlateBffService;
import com.molichuxing.services.business.dto.response.CarCheckDto;
import com.molichuxing.services.business.dto.response.CarLicencePlateDetailDto;
import com.molichuxing.services.business.service.CarCheckBizService;
import com.molichuxing.services.business.service.CarLicencePlateBizService;
import com.molichuxing.services.business.service.VehicleBizService;
import com.molichuxing.services.infrastructure.dto.request.modify.CheckModifyDto;
import com.molichuxing.services.infrastructure.dto.request.modify.DisPdiCheckModifyDto;
import com.molichuxing.services.infrastructure.dto.request.modify.PdiCheckModifyDto;
import com.molichuxing.services.infrastructure.dto.response.*;
import com.molichuxing.services.infrastructure.service.*;
import com.molichuxing.services.property.CarCheckStatusEnum;
import com.molichuxing.services.property.CarsTypeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 车辆检验bff
 * @author xuelin yi
 */
@Service("licencePlateBffService")
public class LicencePlateBffServiceImpl implements LicencePlateBffService {

	private static final Logger logger = LoggerFactory.getLogger(LicencePlateBffServiceImpl.class);

	@Resource
	private CarLicencePlateBizService carLicencePlateBizService;

	@Resource
	private VehicleBizService vehicleBizService;

	@Resource
	private VehicleColorService vehicleColorService;

	@Resource
	private SubcompanyService subcompanyService;

	@Override
	public CarLicencePlateDetailVo getLicencePlate(int carId) throws Exception {
		CarLicencePlateDetailDto licencePlate = carLicencePlateBizService.getLicencePlate(carId);
		String vehicleName = null;
		String vehicleColorName = null;
		String companyName = null;
		if(null != licencePlate) {
			vehicleName = vehicleBizService.getVehicleName(licencePlate.getVehicleId());
			VehicleColorDto vehicleColorDto = vehicleColorService.getVehicleColorByvehicleColorId(licencePlate.getVehicleColorId());
			if(null != vehicleColorDto) {
				vehicleColorName = vehicleColorDto.getName();
			}
			SubcompanyDto subcompanyDto = subcompanyService.getSubcompanyNameById(licencePlate.getSubcompanyId());
			if(null != subcompanyDto) {
				companyName = subcompanyDto.getName();
			}
		}
		return Convert.toCarLicencePlateDetailVo(licencePlate, vehicleName, vehicleColorName, companyName);
	}

	@Override
	public int createLicencePlate(CarLicencePlateCreateVo createVo) throws Exception {
		return carLicencePlateBizService.createLicencePlate(Convert.toCarLicencePlateDetailVo(createVo));
	}

	@Override
	public int modifyLicencePlate(CarLicencePlateModifyVo modifyVo) throws Exception {
		return carLicencePlateBizService.modifyLicencePlate(Convert.toCarLicencePlateModifyDto(modifyVo));
	}
}
